﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenericHtml
{
    /// <summary>
    /// 支持的Column类型
    /// </summary>
    public enum ColumnType
    {
        /// <summary>
        /// 数值
        /// </summary>
        DECIMAL = 1,
        /// <summary>
        /// 字符串
        /// </summary>
        STRING = 2,
        /// <summary>
        /// 日期
        /// </summary>
        DATE = 3,
        /// <summary>
        /// 日期时间
        /// </summary>
        DATETIME = 4,
        /// <summary>
        /// 时间
        /// </summary>
        TIME = 5,
        /// <summary>
        /// 数据字典
        /// </summary>
        DICTIONARY = 6,
        /// <summary>
        /// ID类型
        /// </summary>
        ID = 7
    }

    public class DynamicMetadata
    {
        public int Id { get; set; }

        public string Name { get; set; }
    }

    /// <summary>
    /// 表信息
    /// </summary>
    public class DynamicTable : DynamicMetadata
    {
        public string DisplayName { get; set; }

        public string Template { get; set; }

        public List<DynamicColumn> Columns { get; set; }

        public TableCommand Command { get; set; }

        public DynamicTable()
        {
        }
    }

    /// <summary>
    /// 列信息
    /// </summary>
    public class DynamicColumn : DynamicMetadata
    {
        public string DisplayName { get; set; }

        /// <summary>
        /// 表ID
        /// </summary>
        public int TableId { get; set; }

        /// <summary>
        /// 类型
        /// </summary>
        public ColumnType TypeId { get; set; }

        /// <summary>
        /// 控件ID
        /// </summary>
        public int ControlId { get; set; }

        /// <summary>
        /// 验证类型
        /// </summary>
        public int? RegularId { get; set; }

        /// <summary>
        /// 是否必填
        /// </summary>
        public bool Required { get; set; }

        /// <summary>
        /// 小数点位数
        /// </summary>
        public int? Precision { get; set; }

        /// <summary>
        /// 最小长度(字符串)
        /// </summary>
        public int? MinLength { get; set; }

        /// <summary>
        /// 最大长度(字符串)
        /// </summary>
        public int? MaxLength { get; set; }

        /// <summary>
        /// 最小日期(日期)
        /// </summary>
        public DateTime? MinDate { get; set; }

        /// <summary>
        /// 最大日期(日期)
        /// </summary>
        public DateTime? MaxDate { get; set; }

        /// <summary>
        /// 数据字典分组
        /// </summary>
        public string GroupName { get; set; }

        public bool IsSystemDefault { get; set; }

        public bool IsPrimaryKey { get; set; }

        public bool Edit { get; set; }

        public DynamicColumn()
        {
        }
    }

    /// <summary>
    /// 控件信息
    /// </summary>
    public class DynamicControl : DynamicMetadata
    {
        /// <summary>
        /// 控件HTML模板
        /// </summary>
        public string HtmlTemplate { get; set; }

        public string Content { get; set; }
    }

    public class TableCommand
    {
        public string SelectCommand { get; set; }
        public string InsertCommand { get; set; }
        public string UpdateCommand { get; set; }
        public string DeleteCommand { get; set; }
    }
}
